<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button id="btn">
        点击生成
    </button>
    <script>
        function suiji(m, n) {
            // 定义一个字符串
            var str = '#';
            for (var i = 0; i < 6; i++) {
                var max, min;
                max = n > m ? n : m;
                min = m < n ? m : n;
                // 生成一个0-16之间的随机整数(不含16)
                var num = parseInt(Math.random() * (max - min) + min);
                // 生成一个16进制的颜色
                str += num.toString(16);
                // console.log(str)
            }
            return str;
        }
        btn.onclick = function () {
            document.body.style.background = suiji(0, 16)
        }
    </script>
</body>

</html>